package com.springboot.study.tests.annotation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @Author: guodong
 * @Date: 2021/7/24 16:32
 * @Version: 1.0
 * @Description:
 */
public class EnumStringValidator3 implements ConstraintValidator<EnumValidateAnnotation2, String> {

    private String methodStr;

    private Class<? extends Enum> enumClass;

    @Override
    public void initialize(EnumValidateAnnotation2 constraintAnnotation) {
        methodStr = constraintAnnotation.method();
        enumClass = constraintAnnotation.enumClass();
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if (value == null) {
            return false;
        }
        enumClass.getEnumConstants();
//        if(enums ==null || enums.length == 0){
//            return false;
//        }
        return true;
//        return enums[0].inEnum(value);
    }

}
